//
//  HNSNProductOrderView.m
//  ZYManagementSystem
//
//  Created by 星道 on 17/6/14.
//  Copyright © 2017年 焕宁. All rights reserved.
//

#import "HNSNProductOrderView.h"

@implementation HNSNProductOrderView
{
    IBOutlet UIView *_BackView;
    IBOutlet UILabel *_OrderNO;
    IBOutlet UILabel *_BuyerAcout;
    IBOutlet UILabel *_BuyerName;
    IBOutlet UILabel *_Title;
    IBOutlet UILabel *_PayNO;
    IBOutlet UILabel *_SubTitle;
    __weak IBOutlet UILabel *_Desc;
    
    //需要被隐藏的label都在这
    IBOutletCollection(UILabel) NSArray *LabelArr;
    //一个label的高度是40.5，两行就要减81的高度，原高度82.5
    IBOutlet NSLayoutConstraint *_BackViewHeight;

    IBOutletCollection(NSLayoutConstraint) NSArray *_LabelHeightArr;
    //显示状态相反。。。type为1时隐藏，0时显示
    IBOutlet NSLayoutConstraint *ClassName_Height;
}



/**
 显示自己
 */
- (void)Show {
    //动画展示
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 1;
    }];
}



/**
 移除自己，并关闭界面
 */
- (void)Close {

    [self endEditing:YES];

    //动画开始
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
    
}

/**
 关闭本界面
 */
- (IBAction)Sure:(UIButton *)sender {

    //动画关闭
    [self Close];
}


#pragma mark - 批注老师资金提现详情
//套餐提现的创建
+ (HNSNProductOrderView *(^)(NotesTeacherGetMoneyModel *Model))GetMoneyModel;
{
    return ^(NotesTeacherGetMoneyModel *Model){

        return [[self alloc] initWithGetMoneyModel:Model];

    };
}
/**
 提现状态 -1：未提现或暂不可提现 0：提现中，1：财务拒绝，2：财务同意，3：终审拒绝，4：终审同意，5：已结算 Type:0课程结算 1佣金金额
 当状态为-1时，判断Type的值，0显示未提现 1的话根据 num 值 ，2为未提现，1为暂不可提现
 */
- (NSString *)GetStrForIndex:(NSInteger)Index Type:(NSInteger)Type Num:(NSInteger)Num
{
    switch (Index)
    {
            //Index为-1
        case -1:
        {
            if (Type == 0)
            {
                return @"未提现";
            }
            else
            {
                if (Num == 2)
                {
                    return @"未提现";
                }
                else
                {
                    return @"暂不可提现";
                }
            }
        };break;
        case 0:return @"提现中";break;
        case 1:return @"财务拒绝";break;
        case 2:return @"财务同意";break;
        case 3:return @"终审拒绝";break;
        case 4:return @"终审同意";break;
        case 5:return @"已提现";break;
        default:return @"未知";break;
    }
}

/**
 实例化

 @param GetMoneyModel 数据Model
 */
- (instancetype)initWithGetMoneyModel:(NotesTeacherGetMoneyModel *)GetMoneyModel
{
    self = [[[NSBundle mainBundle] loadNibNamed:[HNSNProductOrderView description] owner:nil options:nil] lastObject];
    if (self) {

        
        //赋值
        _OrderNO.text = [GetMoneyModel.ID stringValue];
        _PayNO.text = GetMoneyModel.tradeNo;
        _SubTitle.text = @"书籍名称:";
        if (GetMoneyModel.courseName.length <= 0)
        {
            _BuyerAcout.text = GetMoneyModel.B_username;
            _Title.text = GetMoneyModel.T_Name;
            _BuyerName.text = GetMoneyModel.B_petName;
        }
        else
        {
            _BuyerAcout.text = GetMoneyModel.accountNumber;
            _Title.text = GetMoneyModel.courseName;
            _BuyerName.text = GetMoneyModel.payName;
        }

        // 显示佣金金额
        if ([GetMoneyModel.type isEqualToNumber:@1])
        {
            [LabelArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

                //赋值
                UILabel *Label = (UILabel *)obj;
                //佣金金额
                if (Label.tag == 1100)
                {
                    Label.text = [NSString stringWithFormat:@"%.2f",[GetMoneyModel.commissionMoney floatValue]];
                }

                // 实付金额
                if (Label.tag == 1101)
                {
                    Label.text = [GetMoneyModel.actualPaid stringValue];
                }
            }];
            _BackViewHeight.constant -= ClassName_Height.constant;
            ClassName_Height.constant = 0;
            [self layoutIfNeeded];
        }
        // 隐藏佣金金额与实付金额
        else
        {
            [_LabelHeightArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

                NSLayoutConstraint *Constraint = (NSLayoutConstraint *)obj;
                _BackViewHeight.constant -= Constraint.constant;
                Constraint.constant = 0;
            }];
            [self layoutIfNeeded];
        }

        //加载
        [[UIApplication sharedApplication].keyWindow addSubview:self];
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREENH_HEIGHT);

        //textfield加上阴影效果
        [[_BackView layer] setMasksToBounds:YES];
        [[_BackView layer] setShadowOffset:CGSizeMake(1, 1)]; // 阴影的范围
        [[_BackView layer] setShadowRadius:3];                // 阴影扩散的范围控制
        [[_BackView layer] setShadowOpacity:1];               // 阴影透明度
        [[_BackView layer] setShadowColor:[UIColor blackColor].CGColor]; // 阴影


        //动画显示
        self.alpha = 0;
        
        //显示
        [self Show];
        
    }
    return self;
}








#pragma mark - 套餐提现
//套餐提现的创建
+ (HNSNProductOrderView *(^)(HNSNGetMoneyModel *))MoneyModel
{
    return ^(HNSNGetMoneyModel *Model){

        return [[self alloc] initWithMoneyModel:Model];

    };
}

/**
 实例化

 @param MoneyModel 数据Model
 */
- (instancetype)initWithMoneyModel:(HNSNGetMoneyModel *)MoneyModel
{
    self = [[[NSBundle mainBundle] loadNibNamed:[HNSNProductOrderView description] owner:nil options:nil] lastObject];
    if (self) {

        NSString *Str = [self GetStrForIndex:[MoneyModel.withdrawFlag integerValue] Type:[MoneyModel.type integerValue] Num:[MoneyModel.num integerValue]];
        _Desc.hidden = [Str isEqualToString:@"未提现"] ? NO:YES;
        //赋值
        _OrderNO.text = [MoneyModel.ID stringValue];
        _PayNO.text = MoneyModel.tradeNo;

        if (MoneyModel.courseName == nil && MoneyModel.payTime.length > 0)
        {
            _BuyerAcout.text = MoneyModel.B_username;
            _Title.text = MoneyModel.T_Name;
            _BuyerName.text = MoneyModel.B_petName;
        }
        else
        {
            _BuyerAcout.text = MoneyModel.accountNumber;
            _Title.text = MoneyModel.courseName;
            _BuyerName.text = MoneyModel.payName;
        }

        // 显示佣金金额
        if ([MoneyModel.type isEqualToNumber:@1])
        {
            [LabelArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

                //赋值
                UILabel *Label = (UILabel *)obj;
                //佣金金额
                if (Label.tag == 1100)
                {
                    Label.text = [NSString stringWithFormat:@"%.2f",[MoneyModel.commissionMoney floatValue]];
                }

                // 实付金额
                if (Label.tag == 1101)
                {
                    Label.text = [MoneyModel.actualPaid stringValue];
                }
            }];
            _BackViewHeight.constant -= ClassName_Height.constant;
            ClassName_Height.constant = 0;
            [self layoutIfNeeded];
        }
        // 隐藏佣金金额与实付金额
        else
        {
            [_LabelHeightArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

                NSLayoutConstraint *Constraint = (NSLayoutConstraint *)obj;
                _BackViewHeight.constant -= Constraint.constant;
                Constraint.constant = 0;
            }];
            [self layoutIfNeeded];
        }

        //加载
        [[UIApplication sharedApplication].keyWindow addSubview:self];
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREENH_HEIGHT);

        //textfield加上阴影效果
        [[_BackView layer] setMasksToBounds:YES];
        [[_BackView layer] setShadowOffset:CGSizeMake(1, 1)]; // 阴影的范围
        [[_BackView layer] setShadowRadius:3];                // 阴影扩散的范围控制
        [[_BackView layer] setShadowOpacity:1];               // 阴影透明度
        [[_BackView layer] setShadowColor:[UIColor blackColor].CGColor]; // 阴影


        //动画显示
        self.alpha = 0;

        //显示
        [self Show];
        
    }
    return self;
}








#pragma mark - 订单列表
//订单列表的创建
+ (HNSNProductOrderView *(^)(HNSNProductOrderModel *))Order
{
    return ^(HNSNProductOrderModel *Model){

        return [[self alloc] initWithOrderModel:Model];

    };
}
/**
 实例化

 @param OrderModel 数据Model
 */
- (instancetype)initWithOrderModel:(HNSNProductOrderModel *)OrderModel
{
    self = [[[NSBundle mainBundle] loadNibNamed:[HNSNProductOrderView description] owner:nil options:nil] lastObject];
    if (self) {

        //赋值
        _OrderNO.text = [OrderModel.ID stringValue];
        _BuyerAcout.text = OrderModel.B_username;
        _BuyerName.text = OrderModel.B_petName;
        _Title.text = OrderModel.T_name;
        _PayNO.text = OrderModel.tradeNo;


        // 显示佣金金额
        if ([OrderModel.type isEqualToNumber:@1])
        {
            [LabelArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

                //赋值
                UILabel *Label = (UILabel *)obj;
                //佣金金额
                if (Label.tag == 1100)
                {
                    Label.text = [NSString stringWithFormat:@"%.2f",[OrderModel.commissionMoney floatValue]];
                }

                // 实付金额
                if (Label.tag == 1101)
                {
                    Label.text = [OrderModel.actualPaid stringValue];
                }
            }];
            _BackViewHeight.constant -= ClassName_Height.constant;
            ClassName_Height.constant = 0;
            [self layoutIfNeeded];
        }
        // 隐藏佣金金额与实付金额
        else
        {
            [_LabelHeightArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

                NSLayoutConstraint *Constraint = (NSLayoutConstraint *)obj;
                _BackViewHeight.constant -= Constraint.constant;
                Constraint.constant = 0;
            }];
            [self layoutIfNeeded];
        }

        //加载
        [[UIApplication sharedApplication].keyWindow addSubview:self];
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREENH_HEIGHT);

        //textfield加上阴影效果
        [[_BackView layer] setMasksToBounds:YES];
        [[_BackView layer] setShadowOffset:CGSizeMake(1, 1)]; // 阴影的范围
        [[_BackView layer] setShadowRadius:3];                // 阴影扩散的范围控制
        [[_BackView layer] setShadowOpacity:1];               // 阴影透明度
        [[_BackView layer] setShadowColor:[UIColor blackColor].CGColor]; // 阴影

        //动画显示
        self.alpha = 0;

        //显示
        [self Show];

    }
    return self;
}



@end
